<%--
  Created by IntelliJ IDEA.
  User: 22246
  Date: 2020/12/16
  Time: 19:00
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>拾光后台</title>
    <link rel="stylesheet" type="text/css" href="https://www.layuicdn.com/layui/css/layui.css" />
    <script src="https://www.layuicdn.com/layui/layui.js"></script></script>
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo">拾光后台</div>
        <!-- 头部区域（可配合layui已有的水平导航） -->
        <ul class="layui-nav layui-layout-left">
            <li class="layui-nav-item"><a href="Home.jsp">控制台</a></li>
            <li class="layui-nav-item"><a href="aaa.jsp">商品管理</a></li>
            <li class="layui-nav-item"><a href="#">用户管理</a></li>
        </ul>
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item">
                <a href="javascript:;">
                    <img src="<%=request.getContextPath()%>/images/方形.png" class="layui-nav-img">
                    拾光
                </a>
                <dl class="layui-nav-child">
                    <dd><a href="">基本资料</a></dd>
                    <dd><a href="">安全设置</a></dd>
                </dl>
            </li>
            <li class="layui-nav-item"><a href="login.jsp">退了</a></li>
        </ul>
    </div>

    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree"  lay-filter="Address">
                <li class="layui-nav-item"><a href="aaa.jsp">图书管理</a></li>
                <li class="layui-nav-item"><a href="Order.jsp">订单管理</a></li>
                <li class="layui-nav-item"><a href="Address.jsp">收货地址管理</a></li>
            </ul>
        </div>
    </div>

    <div class="layui-body">
        <!-- 内容主体区域 -->
        </br>
        <div class="testTable">
            </br>
            <div class="layui-form-item">
                <label class="layui-form-label">搜索用户ID：</label>
                <div class="layui-input-inline">
                    <input id="demoReload" type="text" name="demoReload" required lay-verify="required" placeholder="请输入用户ID" autocomplete="off" class="layui-input">
                </div>
                <button class="layui-btn" id="searchBtn">搜素</button>
                <button type="button" class="layui-btn">添加收货地址</button>
                <hr>
            </div>
        </div>
        <div style="padding: 15px;">
            <table class="layui-hide" id="Address" lay-filter="Address"></table>
            <script type="text/html" id="toolbarDemo">
                <div class="layui-btn-container">
                    <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
                    <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
                    <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>
                </div>
            </script>

            <script type="text/html" id="barDemo">
                <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
            </script>

            <script>
                         layui.use('table', function(){
                             var table = layui.table;
                             var $ = layui.jquery;//获取jquery对象
                             table.render({
                                 elem: '#Address'
                                 ,url:'Address/queryAddress?method=queryAll'
                                 ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
                                 ,defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                                     title: '提示'
                                     ,layEvent: 'LAYTABLE_TIPS'
                                     ,icon: 'layui-icon-tips'
                                 }]
                                 ,title: '地址表'
                                 ,cols: [[
                                     {type: 'checkbox', fixed: 'left'}
                                     ,{field:'id', title:'ID', width:100, fixed: 'left', unresize: true, sort: true}
                                     ,{field:'detail', title:'详细地址', width:200, fixed: 'left', unresize: true, sort: true}
                                     ,{field:'name', title:'收件人姓名', width:250, fixed: 'left', unresize: true, sort: true}
                                     ,{field:'phone', title:'手机号', width:100, fixed: 'left', unresize: true, sort: true}
                                     ,{field:'staffId', title:'用户ID', width:200, fixed: 'left', unresize: true, sort: true}
                                     ,{fixed: 'operation', title:'操作', toolbar: '#barDemo', width:200}
                                 ]]
                                 ,page: true
                             });

                    //头工具栏事件
                    table.on('toolbar(Address)', function(obj){
                        var checkStatus = table.checkStatus(obj.config.id);
                        switch(obj.event){
                            case 'getCheckData':
                                var data = checkStatus.data;
                                layer.alert(JSON.stringify(data));
                                break;
                            case 'getCheckLength':
                                var data = checkStatus.data;
                                layer.msg('选中了：'+ data.length + ' 个');
                                break;
                            case 'isAll':
                                layer.msg(checkStatus.isAll ? '全选': '未全选');
                                break;

                            //自定义头工具栏右侧图标 - 提示
                            case 'LAYTABLE_TIPS':
                                layer.alert('');
                                break;
                        };
                    });

                    //监听行工具事件
                    table.on('tool(Address)', function(obj){
                        var data = obj.data;
                        var value = obj.value ,// 得到修改后的值
                            field = obj.field; // 得到字段
                        console.log(obj)
                        if(obj.event === 'del'){
                            layer.confirm('真的删除行么', function(index){
                                obj.del();
                                layer.close(index);
                                table.reload('Address',{
                                    url:'Address/queryAddress?method=deleteAll',
                                    where:{
                                        //设置需要传递的参数
                                        id:obj.data.id,
                                        method: "deleteAll",
                                    },
                                    page:{
                                        //表示让条件查询从第一页开始，如果未设置从当前页开始查询，此页面的所有数据不纳入条件筛选
                                        curr:1 //从第一页开始
                                    },
                                })
                                window.open("./Address.jsp","_top")
                            });
                        } else if(obj.event === 'edit'){
                            layer.prompt({
                                formType: 2
                                ,title: '修改 ID 为 ['+ data.id +'] 的详细地址'
                                ,value:""
                            }, function zsg(url, jsonEntity, objData) {
                                console.log(url)
                                //发送修改的Ajax请求
                                $.ajax({
                                    type: "post",
                                    url: 'Address/queryAddress?method=updateAll',
                                    data: {
                                        "detail":url,
                                        "id":obj.data.id,
                                    },
                                    success : function(mydata) {
                                        console.log(mydata);
                                        if (mydata.msg == "操作成功") {
                                            layer.msg("信息修改成功", {
                                                "icon": 6,
                                                "time": 2000
                                            });
                                        }
                                        // layer.close(mydata);
                                        window.open("Address.jsp","_top")
                                    }
                                });
                            });
                        }
                    });
                    //给指定元素绑定事件
                    $(document).on('click','#searchBtn',function (data){
                            //获取文本框的值
                            var sreach =$("#demoReload");
                            //调用数据表格的重载方法
                            table.reload('Address',{
                                where:{
                                    //设置需要传递的参数
                                    staffId:sreach.val(),
                                },
                                page:{
                                    //表示让条件查询从第一页开始，如果未设置从当前页开始查询，此页面的所有数据不纳入条件筛选
                                    curr:1//从第一页开始
                                }
                            })
                        }
                    )
                });
            </script>
        </div>
    </div>

    <div class="layui-footer" aling="center">
        <!-- 底部固定区域 -->
        © 六位帝皇丸.com - 陈婉宁组
    </div>
</div>
<script>
    //JavaScript代码区域
    layui.use('element', function(){
        var element = layui.element;

    });
</script>
</body>
</html>
